package GUI;

import Arbori.*;
import Visitor.*;

public class CalculField implements Command {
	private ArboreFunctional a;
	private ArboreFunctional stareA;
	private String stareText;
	private javax.swing.JTextField textCalcul;

	public CalculField(ArboreFunctional a, javax.swing.JTextField tc) {
		this.a = a;
		this.textCalcul = tc;
	}

	public ArboreFunctional execute() {
		getStare();
		Visitor calculVisitor = new CalculVisitor();
		a.acceptVisitor(calculVisitor);
		textCalcul.setText(Double.toString(((CalculVisitor) calculVisitor)
				.getCalcul()));
		return a;
	}

	public String getErr() {
		return "";
	}

	public void getStare() {
		this.stareA = a;
		this.stareText = textCalcul.getText();
	}

	public ArboreFunctional unexecute() {
		this.a = stareA;
		textCalcul.setText(stareText);
		return a;
	}

	public void update(ArboreFunctional af) {
		this.a = af;
	}

}
